/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package playground.denis.thread_examples;

import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author makkalot
 * @licence GPLV2
 */
public class LineProcesser extends Thread{

    private int threadNumber;
    private List<String> globalList = new LinkedList<String>();
    
    
    
    
    LineProcesser(List<String> wordList, int i) {
        this.threadNumber= i;
        this.globalList = wordList;
    }

    @Override
    public void run() {
        
        synchronized(globalList){
        
        while (true){
        
            try{
               if (globalList.size()==0)
               
                   globalList.wait(); 
               
               //process here !
               else{
                
                   String entry = globalList.remove(0);
                   int res = entry.indexOf("denis");
                   
                System.out.println("***********************************************");
                
                   if (res!=-1){
                   
                    System.out.println("We found your String on index : "+res);
                   
                   }
                   
                System.out.println("I 'm the therad "+threadNumber);
                System.out.println("The string i processed was : "+entry);
                System.out.println("***********************************************");
                   
               }
            
            }
            catch(InterruptedException ex){
                
                System.out.println("Im thread and i was terminated ! "+threadNumber);
                return;
            }
        
        }
        
    }
    }

}
